#include <iostream>
#include "comm.hpp"
#include <unistd.h>

int main()
{
    // 约定一个key
    key_t key = GetKey();
    std::cout << "key : " << ToHex(key) << std::endl;
    sleep(3);
    // 创建共享内存
    int shmid = CreateShm(key);
    sleep(5);
    std::cout << "shmid: " << shmid << std::endl;
    // 将shm和进程的地址空间和页表建立映射关系
    std::cout << "开始将shm映射到进程的地址空间中" << std::endl;
    char *s = (char *)shmat(shmid, nullptr, 0);
    sleep(5);

    std::cout << "开始将shm从进程的地址空间中移除" << std::endl;
    shmdt(s);
    sleep(5);

    std::cout << "开始将shm从OS中删除" << std::endl;
    shmctl(shmid, IPC_RMID, nullptr);
    sleep(10);
    return 0;
}